import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { config } from 'dotenv'
import * as path from 'path'
config({ path: path.join(__dirname, '.env.local') })

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue(), vueJsx()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    proxy: {
      '/index.umd.js': {
        target: 'http://10.0.6.148:2024',
        changeOrigin: true
      },
      '/style.css': {
        target: 'http://10.0.6.148:2024',
        changeOrigin: true
      },
      '/api': {
        target: process.env.VITE_PROXY,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  }
})
